package com.example.mydemo.threadPool;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * 有界队列
 */
public class ArrayBlockingQueueDemo {
    /**
     * 有界队列
     *  队列有大小限制
     */
    final static ArrayBlockingQueue<Runnable> arrayBlockingQueue = new ArrayBlockingQueue<>(8);
    public static void main(String[] args) {
        ThreadPoolExecutor executor = new ThreadPoolExecutor(1, 2, 5, TimeUnit.SECONDS
                , arrayBlockingQueue, Executors.defaultThreadFactory(), new ThreadPoolExecutor.AbortPolicy());

        for (int i = 0; i < 10; i++) {
            executor.execute(()->{
                System.out.println(Thread.currentThread().getName());
            });
        }

    }
}
